<template>
    <div class="evaluate">
        <van-form @submit="onSubmit">

            <van-field :name="item.name" :label="item.label" v-for="(item,i) in infos" :key="i">
                <template #input>
                    <span v-if="item.name!='evaluate'">
                        <van-rate v-model="item.value"/>
                    </span>
                    <span v-else>
                        <van-field :name="item.name" type="textarea" v-model="item.value"></van-field>
                    </span>
                </template>

            </van-field>

            <div style="margin: 16px;">
                <van-button round block type="info" native-type="submit">确认</van-button>
            </div>
        </van-form>
    </div>
</template>

<script>
import {evaluateGoods} from "@/api/goods";

export default {
    name: "BuyerEvaluate",
    data() {
        return {
            goodsRate: 0,
            sellerRate: 0,
            deliveryRate: 0,
            comment: "",
            infos: [
                {name: "goodsRate", label: "商品描述", value: 0},
                {name: "sellerRate", label: "卖家态度", value: 0},
                {name: "deliveryRate", label: "物流服务", value: 0},
                {name: "evaluate", label: "评价", value: ""},
            ]
        }
    },
    created() {

    },
    watch: {},
    computed: {},
    methods: {
        async onSubmit(values) {
            console.log(values)
            values["order_id"]=this.$route.query.orderId
            let result = await evaluateGoods(values);
            if (this.utils.resultBool(result)) {
                this.$router.back()
            } else {
                this.$toast(`提交评价失败`)
            }
        },
        currentType(name) {
            return name === 'comment' ? 'textarea' : 'text'
        }
    }
}
</script>

<style lang="scss" scoped>
.evaluate {
    text-align: center;
    margin-top: 100px;
}
</style>
